#include "util.hpp"
#include "data.hpp"
#include "server.hpp"

void FileTest()
{
    aod::FileUtil("./www").CreateDirectory();
    aod::FileUtil("./www/index.html").SetContent("<html></html>");
    std::string body;
    aod::FileUtil("./wwww/index.html").GetContent(&body);
    std::cout << body <<std::endl;
    std::cout << aod::FileUtil("./www/index.html").Size()<<std::endl;
}
void JsonTest()
{
    Json::Value val;
    val["name"] = "zhang fei";
    val["age"] = 18;
    val["sex"] = "man";
    val["score"].append(78);
    val["score"].append(95);
    val["score"].append(59.5);

    std::string body;
    aod::JsonUtil::Serialize(val,&body);
    std::cout<< body<< std::endl;

    Json::Value stu;
    aod::JsonUtil::UnSerialize(body,&stu);
    std::cout<< stu["name"].asString() << std::endl;
    std::cout<< stu["sex"].asString() << std::endl;
    std::cout<< stu["age"].asString() << std::endl;

    for(auto &e:stu["score"])
    std::cout<< e.asFloat() << std::endl;
}
void DataTset()
{
    aod::TableVideo tb_video;
    Json::Value video;
    // video["name"] = "狮子王辛巴";
    // video["info"] = "辛巴的成长";
    // video["video"] = "./video/The King of Lion.mp4";
    // video["image"] = "./image/The King of Lion.jpg";

    // tb_video.Insert(video);
    //tb_video.Update(8,video);
    //tb_video.Delete(8);
  
    //tb_video.SelectAll(&video);
    //tb_video.SelectOne(2,&video);
    tb_video.SelectLike("狮子",&video);   
    std::string body;
    aod::JsonUtil::Serialize(video,&body);
    std::cout << body <<std::endl;
}
void ServerTest()
{
    aod::Server server(9090);
    server.RunModule();
}

int main()
{
    //FileTest(); 
    //JsonTest();
    //DataTset();
    ServerTest();

    return 0;    
}